<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>

<body>
<?php 

	require_once ('appvars.php');
	require_once ('connectvars.php');
	
	if (isset($_POST['submit'])){
		$name=$_POST['name'];
		$score=$_POST['score'];
		$screenshot=$_FILES['screenshot']['name'];
		$screenshot_type=$_FILES['screenshot']['type'];
		$screenshot_size=$_FILES['screenshot']['size'];
		if($_FILES['screenshot']['error']==0){
			$target=GW_UPLOADPATH .$screenshot;
			if (move_uploaded_file($_FILES['screenshot']['tmp_name'], $target)){
				$dbc=mysqli_connect(DB_HOST,DB_USER,DB_PASSWORD,DB_NAME);
				
				$query="insert into guitarwars(date,name,score,screenshot) values ( now(),'$name','$score','$screenshot')";
				mysqli_query($dbc,$query);
				
				echo '<p>Thanks for adding your new high score! It will be reviewed and added to the high score list as soon as possible.</p>';
	            echo '<p><strong>Name:</strong> ' . $name . '<br />';
	            echo '<strong>Score:</strong> ' . $score . '<br />';
	            echo '<img src="' . GW_UPLOADPATH . $screenshot . '" alt="Score image" /></p>';
	            
	            $name="";
	            $score="";
	            $screenshot="";
			}
			else{
				echo '<p class="error">Sorry, there was a problem uploading your screen shot image.</p>';
			}
		}
	}

?>
	<form enctype="multipart/form-data" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
		<input type="hidden" name="MAX_FILE_SIZE" value="<?php echo GW_MAXFILESIZE; ?>" />
        <label for="name">Name:</label>
    <input type="text" id="name" name="name" value="<?php if (!empty($name)) echo $name; ?>" /><br />
    	<label for="score">Score:</label>
    <input type="text" id="score" name="score" value="<?php if (!empty($score)) echo $score; ?>" /><br />
    <label for="screenshot">Screen shot:</label>
    <input type="file" id="screenshot" name="screenshot" />
    <hr />
    <input type="submit" value="Add" name="submit" />
	</form>
<a href="javascript:history.go(-1)">Back</a>
</body>
</html>